#include "main.h"
#include "gui.h"
#include "Window.h"
//Irá incluir funções de desenho da GUI:
//---Container para janela OpenGL
//---Container para janela opencv - live feed
//---Opcional: Botão para fazer toggle entre controlo 
//-----------------------------teclado/motion capture




void glutText(float posx, float posy, void *font, char* text){
 
  if(!text || !strlen(text)) return;
  glColor3f(0.0,0.0,0.0);
  glRasterPos2f(posx,posy);
  while (*text) {
    glutBitmapCharacter(font, *text);
    text++;
  }
}  


void draw(){ //to be moved/deleted
  
  glClearColor(0.4,0.0,0.0,1.0);
  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glutSwapBuffers();

}

void draw2(){ //idem

  glClearColor(1.0, 1.0, 0.5, 0.0); // light yellow background
  glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  glutText(-1.0f, 0.6f, GLUT_BITMAP_HELVETICA_12, "Webcam Window");
  glutSwapBuffers();
  
}

void draw3(){
  glClearColor(1.0, 0.0, 0.5, 0.0); // light yellow background
  glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  glutText(100.0f, 100.0f, GLUT_BITMAP_HELVETICA_12, "Game Window");
  glutSwapBuffers();
  
}

void draw4(){
  glClearColor(0.0, 1.0, 0.5, 0.0); // light yellow background
  glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  glutText(-1.0f, 0.0f, GLUT_BITMAP_HELVETICA_12, "Status Window");
  glutSwapBuffers();
  
}

void initGUI(){
  Window mainWindow,webcamWindow,gameWindow,statusWindow;
  
  mainWindow = Window(0, //janela nao inicializada ainda
		      MAIN_WINDOW_WIDTH,
		      MAIN_WINDOW_HEIGHT,
		      MAIN_WINDOW_POSX, 
		      MAIN_WINDOW_POSY,
		      MAIN_WINDOW_NAME);
  
  webcamWindow = Window(0, //janela nao inicializada ainda
			WEBCAM_WINDOW_WIDTH,
			WEBCAM_WINDOW_HEIGHT,
			WEBCAM_WINDOW_POSX, 
			WEBCAM_WINDOW_POSY,
			WEBCAM_WINDOW_NAME);
  
  gameWindow = Window(0, //janela nao inicializada ainda
		      GAME_WINDOW_WIDTH,
		      GAME_WINDOW_HEIGHT,
		      GAME_WINDOW_POSX, 
		      GAME_WINDOW_POSY,
		      GAME_WINDOW_NAME); 
  
  statusWindow = Window(0, //janela nao inicializada ainda
			STATUS_WINDOW_WIDTH,
			STATUS_WINDOW_HEIGHT,
			STATUS_WINDOW_POSX, 
			STATUS_WINDOW_POSY,
			STATUS_WINDOW_NAME); 
  
  glutInitWindowPosition(mainWindow.getPosX(),
			 mainWindow.getPosY());
  glutInitWindowSize(mainWindow.getWidth(),
		     mainWindow.getHeight());
  mainWindow.setHandle(glutCreateWindow(mainWindow.getName().c_str()));
  glutSetWindow(mainWindow.getHandle());
  glutDisplayFunc(draw);
  
  webcamWindow.setHandle(glutCreateSubWindow(mainWindow.getHandle(),
					     webcamWindow.getPosX(),
					     webcamWindow.getPosY(),
					     webcamWindow.getWidth(),
					     webcamWindow.getHeight()));
  
  
  glutSetWindow(webcamWindow.getHandle());
  glutDisplayFunc(draw2);
  

  gameWindow.setHandle(glutCreateSubWindow(mainWindow.getHandle(),
					   gameWindow.getPosX(),
					   gameWindow.getPosY(),
					   gameWindow.getWidth(),
					   gameWindow.getHeight()));

  glutSetWindow(gameWindow.getHandle());
  glutDisplayFunc(draw3);
  
  statusWindow.setHandle(glutCreateSubWindow(mainWindow.getHandle(),
					     statusWindow.getPosX(),
					     statusWindow.getPosY(),
					     statusWindow.getWidth(),
					     statusWindow.getHeight()));

  glutDisplayFunc(draw4);
  

}
